﻿using System;

namespace SmartParking.Data
{
    public class SmartParkingDatabase : IDisposable
    {
        private static SmartParkingContext _context = null;
        public static SmartParkingContext Context
        {
            get
            {
                if (_context == null)
                    _context = new SmartParkingContext();
                return _context;
            }
        }

        public virtual void Dispose()
        {
            _context.Dispose();
        }

        //public static void CancelChanges(EntityState state = EntityState.Added | EntityState.Modified | EntityState.Deleted)
        //{
        //    var entries =
        //        Context.ObjectStateManager.GetObjectStateEntries(state);
        //    foreach (var entry in entries)
        //    {
        //        if (entry.State == EntityState.Modified || entry.State == EntityState.Deleted)
        //        {
        //            Context.Refresh(RefreshMode.StoreWins, entry.Entity);
        //        }
        //        else if (entry.State == EntityState.Added)
        //        {
        //            Context.Detach(entry.Entity);
        //        }
        //    }
        //    Context.SaveChanges();
        //}
    }
}
